<script>
/**
 * Orders Component
 */
import Multiselect from "vue-multiselect";
export default {
  components: { Multiselect },
  data() {
    return {
      title: "Orders",
      items: [
        {
          text: "Ecommerce",
        },
        {
          text: "Orders",
          active: true,
        },
      ],
      ordersData: [
        {
          type: "资讯数据",
          grouping: "1",
          labelNum: "53",
          signNum: "12,123,761",
          unmarkNum: "22,356",
          percentage:"92%",
          correctNum:"232,918",
          onedayNum:"160,221",
          daily:"21"
        },{
          type: "工商数据",
          grouping: "1",
          labelNum: "235",
          signNum: "553,761",
          unmarkNum: "356",
          percentage:"98%",
          correctNum:"37,301",
          onedayNum:"2,998,361",
          daily:"3"
        },{
          type: "招标数据",
          grouping: "5",
          labelNum: "230",
          signNum: "398,021,321",
          unmarkNum: "321",
          percentage:"91%",
          correctNum:"28,769",
          onedayNum:"1,427,265",
          daily:"4"
        },{
          type: "招聘数据",
          grouping: "3",
          labelNum: "35",
          signNum: "5,763,523",
          unmarkNum: "-",
          percentage:"100%",
          correctNum:"128",
          onedayNum:"23,213,421",
          daily:"14"
        },{
          type: "微信公众号",
          grouping: "4",
          labelNum: "20",
          signNum: "32,452,343",
          unmarkNum: "653",
          percentage:"94%",
          correctNum:"36,482",
          onedayNum:"3,213,213",
          daily:"33"
        },{
          type: "短视频",
          grouping: "4",
          labelNum: "34",
          signNum: "37,364,123",
          unmarkNum: "1,182",
          percentage:"99%",
          correctNum:"36,452",
          onedayNum:"8,876,311",
          daily:"60"
        },{
          type: "微博数据",
          grouping: "2",
          labelNum: "21",
          signNum: "77,645,129",
          unmarkNum: "65,321",
          percentage:"91%",
          correctNum:"887",
          onedayNum:"9,983,651",
          daily:"71"
        },{
          type: "证券数据",
          grouping: "3",
          labelNum: "241",
          signNum: "76,483,917",
          unmarkNum: "876",
          percentage:"95%",
          correctNum:"887,364",
          onedayNum:"8,765,234",
          daily:"88"
        },{
          type: "政府数据",
          grouping: "5",
          labelNum: "75",
          signNum: "77,645,109",
          unmarkNum: "3,982",
          percentage:"92%",
          correctNum:"66,531",
          onedayNum:"6,541,934",
          daily:"91"
        },{
          type: "标准数据",
          grouping: "1",
          labelNum: "34",
          signNum: "36,351,921",
          unmarkNum: "3,837",
          percentage:"95%",
          correctNum:"8,836",
          onedayNum:"8,649,311",
          daily:"83"
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "type", label: "标签类型" },
        { key: "grouping", label: "标签分组" },
        { key: "labelNum",  label: "标签数量" },
        { key: "signNum",  label: "标记数量" },
        { key: "unmarkNum", label: "未标数量" },
        { key: "percentage", label: "标记百分比" },
        { key: "correctNum",  label: "修正数量" },
        { key: "onedayNum",  label: "24小时标记量" },
        { key: "operation",  label: "操作" },
        { key: "daily", label: "关联客户" },
      ],
      showModal: false,
      showModalGrouping: false,
      classificationName: "",
      groupingName: "",
      labelType: "",
      labelTypeList: ['类型一','类型二'],
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发分页");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    handleCommand(v){
      console.log(v);
      if(v=="查看标签"){
        this.$router.push({
          path: '/lable/editLabel'
        });
      }else if(v=="查看数据"){
        this.$router.push({
          path: '/lable/signList'
        });
      }
    },
    handleClose(){
      this.showModal = false
      this.showModalGrouping = false
    },
    addLabel(){
      this.$router.push('/lable/addLabel')
    }
  },
};
</script>

<template>
  <div class="card">
    <div class="card-body pt-0">
      <!-- 搜索 -->
      <div class="search-box">
        <div class="searchNum">为您搜索到<span>5,000+</span>条标签信息</div>
        <div>
          <b-dropdown dropup variant="secondary" class="butn">
            <template slot="button-content">
              <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
              <span style="margin:0 20px 0 6px;">标签管理</span>
              <i class="mdi mdi-chevron-up"></i>
            </template>
            <b-dropdown-item-button @click="addLabel">创建标签</b-dropdown-item-button>
            <b-dropdown-item-button @click="showModalGrouping=true">创建分组</b-dropdown-item-button>
            <b-dropdown-item-button @click="showModal=true">创建分类</b-dropdown-item-button>
          </b-dropdown>
        </div>
      </div>

      <div class="table-responsive">
        <b-table
          class="table-centered"
          :items="ordersData"
          :fields="fields"
          responsive="sm"
          :per-page="perPage"
          :current-page="1"
          thead-class="thead-light"
          @filtered="onFiltered"
        >
          <template v-slot:cell(correctNum)="row">
            <div class="badge font-size-12 badge-soft-success">{{ row.value}}</div>
          </template>
          <template v-slot:cell(onedayNum)="row">
            <div class="badge font-size-12 badge-soft-primary">{{ row.value}}</div>
          </template>
          <template v-slot:cell(operation)>
            <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
                更多<i class="el-icon-arrow-down font-size-12 el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="查看数据">查看数据</el-dropdown-item>
                <el-dropdown-item command="查看标签">查看标签</el-dropdown-item>
                <el-dropdown-item command="添加分组">添加分组</el-dropdown-item>
                <el-dropdown-item command="添加标签">添加标签</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </b-table>
      </div>
      <div class="row">
        <div class="col">
          <div class="dataTables_paginate paging_simple_numbers float-right">
            <ul class="pagination pagination-rounded mb-0">
              <!-- pagination -->
              <b-pagination
                v-model="currentPage"
                :total-rows="totalRows"
                :per-page="perPage"
              ></b-pagination>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title="添加分类"
      :visible.sync="showModal"
      width="40%"
      :before-close="handleClose">
      <form>
        <div class="form-group">
          <label for="productname">分类名称</label>
          <b-form-input
            for="text"
            v-model="classificationName"
            placeholder="请输入一个分类名称，不能大于6个字，不能有特殊符号"
          ></b-form-input>
        </div>
      </form>
      <span slot="footer" class="dialog-footer">
        <b-button variant="primary" @click="showModal = false">
          提交
        </b-button>
      </span>
    </el-dialog>
    <el-dialog
      title="添加分组"
      :visible.sync="showModalGrouping"
      width="40%"
      :before-close="handleClose">
      <form>
        <div class="form-group">
          <label for="productname">标签类型</label>
          <multiselect
            v-model="labelType"
            :options="labelTypeList"
            placeholder="请选择一个标签数据分类项"
          ></multiselect>
        </div>
        <div class="form-group">
          <label for="productname">分组名称</label>
          <b-form-input
            for="text"
            v-model="groupingName"
            placeholder="请输入一个分组名称，不能大于6个字，不能有特殊符号"
          ></b-form-input>
        </div>
      </form>
      <span slot="footer" class="dialog-footer">
        <b-button variant="primary" @click="showModalGrouping = false">
          提交
        </b-button>
      </span>
    </el-dialog>
  </div>
</template>
<style lang="scss" scoped>
.search {
  float: left;
  width: 300px;
  margin-bottom: 20px;
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.search-box{
  padding: 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.searchNum{
  span{
    font-size: 1rem;
    color: #3444c1;
    margin: 0 4px;
    font-weight: 600;
  }
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
::v-deep .el-dialog__footer{
  text-align: center;
}
</style>
 

